package com.hualan.controller;

import com.github.pagehelper.PageInfo;
import com.hualan.pojo.ConsultComment;
import com.hualan.pojo.Result;
import com.hualan.service.ConsultConmmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consultConmment")
public class ConsultConmmentController {
    @Autowired
    private ConsultConmmentService consultCommentService;
    //分页查询所有信息
    @GetMapping("/getAllPage")
    public Result getAllPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize, String evaluationContent){
        PageInfo<ConsultComment> pageInfo = consultCommentService.selectAllPage(pageNum, pageSize,evaluationContent);
        return Result.success(pageInfo);
    }





    //查询所有
    @GetMapping("/details")
    public Result getCommentDetails() {
        List<ConsultComment> content= consultCommentService.getCommentDetails();
        return Result.success(content) ;
    }
    //根据id删除
    @DeleteMapping("/remove/{id}")
    public Result deleteByPrimaryKey(@PathVariable Long id) {
        int aa= consultCommentService.deleteByPrimaryKey(id);
        if (aa==0) {
            System.out.println("失败");
        }else {
            System.out.println("成功");
        }
        return Result.success("删除成功");
    }
    //逻辑删除
    @PutMapping ("/removeluoji/{id}")
    public Result luojidelete(@PathVariable Long id){
        int bb = consultCommentService.deleteLogic(id);
        if (bb==0){
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }
        return Result.success("删除成功");
    }

    // 批量删除
    @DeleteMapping("/batchRemove")
    public Result deleteBatch(@RequestBody List<Long> ids) {
        int result = consultCommentService.deleteBatch(ids);
        if (result == 0) {
            System.out.println("批量删除失败");
            return Result.error("批量删除失败");
        } else {
            System.out.println("批量删除成功");
            return Result.success("批量删除成功");
        }
    }


}
